define(function (require) {

    var $ = require("zepto");

    var callback = function (event) {
        if ("no" !== $(event.currentTarget).attr("data-event")) {
            event.preventDefault();
            event.stopPropagation();
        }
        var $node = $(event.currentTarget);
        var action = $node.attr("data-action") || "";
        var reg = /^([a-zA-Z0-9_]+):\/\/([a-zA-Z0-9_]+)$/;
        var funcArr = reg.exec(action);
        var option = {node: $node, e_node: event, _node: event.currentTarget};
        if (funcArr) {
            var func = funcArr[1];
            var num = funcArr[2];
            (func in $) && (num in $[func]) && $[func][num].call(null, option);
        }
    };

    var global = {
        _click: "ontouchstart" in window ? "tap" : "click", _events: {},
        _windowHeight: $(window).height(),
        _windowWidth: $(window).width(),
        _rotateNode: $(".p-ct"),
        _isMotion: !!window.DeviceMotionEvent,
        _elementStyle: document.createElement("div").style,
        _UC: RegExp("Android").test(navigator.userAgent) && RegExp("UC").test(navigator.userAgent) ? true : false,
        _weixin: RegExp("MicroMessenger").test(navigator.userAgent) ? true : false, _iPhoen: RegExp("iPhone").test(navigator.userAgent) || RegExp("iPod").test(navigator.userAgent) || RegExp("iPad").test(navigator.userAgent) ? true : false,
        _Android: RegExp("Android").test(navigator.userAgent) ? true : false, _IsPC: function () {
            var agent = navigator.userAgent;
            var system = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
            for (var i = 0; system.length > i; i++) {
                if (agent.indexOf(system[i]) > 0) {
                    return false;
                }
            }
            return true;
        },
        _isOwnEmpty: function (t) {
            for (var e in t) {
                if (t.hasOwnProperty(e)) {
                    return false;
                }
            }
            return true;
        },
        _vendor: function () {
            var brower = ["t", "webkitT", "MozT", "msT", "OT"];
            for (var n = 0, i = brower.length; i > n; n++) {
                var t = brower[n] + "ransform";
                if (t in this._elementStyle) {
                    return brower[n].substr(0, brower[n].length - 1);
                }
            }
            return false;
        },
        _prefixStyle: function (t) {
            return this._vendor() === false ? false : "" === this._vendor() ? t : this._vendor() + t.charAt(0).toUpperCase() + t.substr(1);
        },
        _hasPerspective: function () {
            var t = this._prefixStyle("perspective")in this._elementStyle;
            return t && "webkitPerspective"in this._elementStyle && this._injectStyles("@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}", function (e) {
                t = 9 === e.offsetLeft && 3 === e.offsetHeight;
            });
        },
        _injectStyles: function (t, e, n, i) {
            var a, o, r, s, l = document.createElement("div"), c = document.body, u = c || document.createElement("body"), d = "modernizr";
            if (parseInt(n, 10))
                for (; n--; )
                    r = document.createElement("div"), r.id = i ? i[n] : d + (n + 1), l.appendChild(r);
            return a = ["&#173;", '<style id="s', d, '">', t, "</style>"].join(""), l.id = d, (c ? l : u).innerHTML += a, u.appendChild(l), c || (u.style.background = "", u.style.overflow = "hidden", s = docElement.style.overflow, docElement.style.overflow = "hidden", docElement.appendChild(u)), o = e(l, t), c ? l.parentNode.removeChild(l) : (u.parentNode.removeChild(u), docElement.style.overflow = s), !!o
        },
        _translateZ: function () {
            return this._hasPerspective ? " translateZ(0)" : ""
        },
        _handleEvent: function (t) {
            if (this._events[t]) {
                var e = 0, n = this._events[t].length;
                if (n)
                    for (; n > e; e++)
                        this._events[t][e].apply(this, [].slice.call(arguments, 1))
            }
        },
        _on: function (t, e) {
            this._events[t] || (this._events[t] = []), this._events[t].push(e)
        },
        execHandler: function (t) {
            if (t && t instanceof Object) {
                var e = t.callback || null, n = t.opts || [], i = t.context || null, a = t.delay || -1;
                e && e instanceof Function && ("number" == typeof a && a >= 0 ? setTimeout(function () {
                    e.call(i, n)
                }, a) : e.call(i, n))
            }
        },
        execAfterMergerHandler: function (t, n) {
            t && t instanceof Object && (t.opts || [], t.opts = $.extend(t.opts, n)), this.execHandler(t)
        },
        _scrollStop: function () {
            $("body").addClass("f-ofh");
            $(window).on("touchmove", this._scrollControl);
            $(window).on("scroll", this._scrollControl);
        },
        _scrollStart: function () {
            $("body").removeClass("f-ofh");
            $(window).off("touchmove");
            $(window).off("scroll");
        },
        _scrollControl: function (t) {
            return t.preventDefault();
        },
        setActionHook: function () {
            $("body").on(global._click, "[data-action]", callback);
        },
        injectAction: function (t) {
            $.extend($.Action, t);
        },
        loadingPageShow: function (t) {
            t.length >= 1 && t.show();
        },
        loadingPageHide: function (t) {
            t.length >= 1 && t.hide();
        },
        refresh: function () {
            this._windowHeight = $(window).height();
            this._windowWidth = $(window).width();
        }};
    return global;
});